local jilie = fk.CreateSkill {
  name = "th_jilie",
  max_phase_use_time = 2,
}

jilie:addEffect("active", {
  prompt = "#th_jilie",
  anim_type = "offensive",
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player and table.find(to_select:getCardIds("h"), function(cid)
      return Fk:getCardById(cid, true):getMark("th_jilie-turn") == 0
    end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = table.filter(target:getCardIds("h"), function(cid)
      return Fk:getCardById(cid, true):getMark("th_jilie-turn") == 0
    end)
    local showed = room:askToCards(target, {
      min_num = 1,
      max_num = #cards,
      include_equip = false,
      skill_name = jilie.name,
      cancelable = false,
      pattern = ".|.|.|.|.|.|"..table.concat(cards, ","),
      prompt = "#th_jilie-show"
    })
    target:showCards(showed)
    if #target:getCardIds("h") == 0 then return end
    local card = room:askToChooseCard(player, {
      target = target,
      flag = "h",
      skill_name = jilie.name,
      prompt = "#th_jilie-view::" .. target.id
    })
    room:moveCards({
      ids = {card},
      from = target,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = jilie.name,
      proposer = player,
    })
    room:sendFootnote({ card }, {
      type = "$$TurnOverCard",
      from = player.id,
    })
    if Fk:getCardById(card, true):getMark("th_jilie-turn") ~= 0 then
      room:obtainCard(player, card, true, fk.ReasonPrey, player, jilie.name)
    elseif not player:isNude() then
      local dis = room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = jilie.name,
        cancelable = true,
        prompt = "#th_jilie-discard::" .. target.id
      })[1]
      if dis and target:isAlive() then
        room:damage{
          from = player,
          to = target,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = jilie.name,
        }
      end
    end
    room:cleanProcessingArea({card}, jilie.name)
  end
}, { check_skill_limit = true })

jilie:addEffect(fk.CardShown, {
  is_delay_effect = true,
  global = true,
  mute = true,
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(data.cardIds) do
      room:setCardMark(Fk:getCardById(id, true), "th_jilie-turn", 1)
    end
  end,
})

Fk:loadTranslationTable{
  ["th_jilie"] = "疾烈",
  [":th_jilie"] = "出牌阶段限两次，你可以令一名其他角色展示任意张本回合未展示过的手牌，然后你亮出其一张手牌，若此牌本回合展示过，你获得之；否则你可以弃置一张牌对其造成1点火焰伤害。",
  ["#th_jilie"] = '疾烈：令一名其他角色展示任意张本回合未展示过的手牌，然后你亮出其一张手牌，<br>' ..
  "若此牌本回合展示过，你获得之；否则你可以弃置一张牌对其造成1点火焰伤害",

  ["#th_jilie-show"] = "疾烈：你须展示任意张本回合未展示过的手牌",
  ["#th_jilie-view"] = "疾烈：请亮出 %dest 一张手牌",
  ["#th_jilie-discard"] = "疾烈：你可以弃置一张牌，对 %dest 造成1点火焰伤害",
}

return jilie